package bishihuizong;


import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by JiaJia on 2019/9/16 0016.
 */
public class Kuaishou04 {
    public static void main(String[] args) {
        /*Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            int n=scanner.nextInt();
            int[] num=new int[n];
            for (int i = 0; i <n ; i++) {
                num[i]=scanner.nextInt();
            }
            System.out.println(num);
        }scanner.close();*/
        int[] num=new int[]{1,4,2,5,3};
        System.out.println(subsequnceLength(num));
    }
    public static int subsequnceLength(int[] num){
        Arrays.sort(num);
        if (num.length==1)
            return 1;
        if (num.length==2)
            return 2;
        int m=num.length;
        int[] dp=new int[m];
        dp[0]=1;dp[1]=2;
        for (int i = 2; i <m ; i++) {
            if (num[i]-num[i-1]==num[i-1]-num[i-2]){
                dp[i]=dp[i-1]+1;
            }else {
                dp[i]=2;
            }
        }
        int res=0;
        for (int i = 0; i <dp.length ; i++) {
            res=Math.max(res,dp[i]);
        }
        return res;
    }
        /*int max=0;
        for (int i = 0; i <num.length ; i++) {
            for (int j = i+1; j <num.length ; j++) {
                int cnt=2;
                int dis=num[j]-num[i];
                int temp=num[j]+dis;
                for (int k = j+1; k <num.length ; k++) {
                    if (temp==num[k]){
                        temp+=dis;
                        cnt+=1;
                    }
                }
                if (cnt>max)max=cnt;
                }
            }
        return max;
        }*/
}